package my.cloud.study.hystrix;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import my.cloud.study.User;
import my.cloud.study.service.HelloRemoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Slf4j
@Component
public class HelloHystrixFallbackFactory implements FallbackFactory<HelloRemoteService> {

    @Autowired
    HelloRemoteServiceImpl service;

    public HelloRemoteService create(Throwable cause) {
        return service;
    }

    @Service
    class HelloRemoteServiceImpl implements HelloRemoteService{
        public User userInfo() {
            User user = new User();
            user.setName("Hystrix Name");
            user.setId("DEFAULT-HYSTRIX-ID-1");
            user.setAddress("This is the Hystrix address");
            return user;
        }

        public String info(String id) {
            return "Hystrix information with id: "+id;
        }
    }
}
